package com.ithaime.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.RequestPath;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.net.URI;

/**
 * @author hrz
 * @version 1.0
 * @date 2020/6/27 20:31
 */
@Component
public class UrlFilter implements GlobalFilter, Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println("经过第3个过滤器UrlFilter");
        ServerHttpRequest request = exchange.getRequest();
        String path = request.getURI().getPath();
        //打断点看结果用
        URI uri = request.getURI();
        RequestPath path1 = request.getPath();
        
        System.out.println("url是"+path);
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 2;
    }
}
